using System;
using System.Collections.Generic;
using System.Text;
using Accountability4net;
using System.Xml;

namespace Accountability4net.FileMonengineProvider
{
    public class FileAction: BaseAction
    {
        private FileMonengineProvider provider_;
        public FileAction(ActionType type, IAccount account, Decimal amount, FileMonengineProvider provider)
            : base(type, account, amount)
        {
            provider_ = provider;
        }

        public static IAction Parse(XmlNode node, FileMonengineProvider provider)
        {
            FileAction action = new FileAction(
                (ActionType)Enum.Parse(typeof(ActionType), node.Attributes["type"].Value)
                , provider.GetAccount(int.Parse(node.Attributes["account"].Value))
                , Decimal.Parse(node.Attributes["amount"].Value)
                ,provider);
            return action;
        }

        public XmlNode Write(XmlNode element)
        {
            XmlNode node = element.OwnerDocument.CreateElement("action", element.NamespaceURI);
            element.AppendChild(node);
            XmlUtility.CreateAttribute(node, "account", Account.Number);
            XmlUtility.CreateAttribute(node, "amount", Amount);
            XmlUtility.CreateAttribute(node, "type", Type);
            return node;
        }
    }
}
